from sanic import Sanic
from sanic_jsonrpc import SanicJsonrpc

from registry import RegistryProvider, provider_address

INTERFACE = 'com.sanic.demo.Hi'
PORT = 8000
ZOO_ADDRESS = "127.0.0.1:2181"

registry_provider = RegistryProvider(ZOO_ADDRESS, "MyApp", provider_address(ZOO_ADDRESS), PORT)
registry_provider.registry(INTERFACE, "hi")

app = Sanic(__name__)
jsonrpc = SanicJsonrpc(app, post_route='/dubbo/' + INTERFACE)


@jsonrpc
async def hi(name: str):
    return "Hi %s" % name


if __name__ == "__main__":
    app.run(host='0.0.0.0', port=PORT)
